pluginHome = new File( grailsSettings.projectPluginsDir.path ).listFiles().find { it.name.startsWith('cloud-tools-') }
if(pluginHome == null) pluginHome = "."

includeTargets << new File( "${pluginHome}/scripts/CloudToolsInit.groovy" )

target('default': "curl") {
	curl()
}

target(curl: "The implementation task") {
	depends( initCloudToolsService)
    cloudToolsService.withCluster { clusterManager, clusterName, cluster ->
		def method = "GET"
		if(System.getProperty("cloudtools.curl.path") != null){
			def path = System.getProperty("cloudtools.curl.path")
			if(System.getProperty("cloudtools.curl.method") != null){
				method = System.getProperty("cloudtools.curl.method")
			}
			cluster.getClusterInstance().getWebServerTier().curl(path, method);
			event('StatusFinal', ['Finished with curl on ' + path + ' and ' + method])
		}else{
			event('StatusError', ['You must specify cloudtools.curl.path.  Example:\ngrails -Dcloudtools.curl.path=<path> -Dcloudtools.curl.method=<method (GET is default)> cloud-tools-curl'])
		}
	}
}
